<template>
	<view class="content">
		<nav-bar title='会员购买' black bgColor="rgba(255,255,255,0)" titleColor="#333333"></nav-bar>
		<view class="head-box">
			<view class="sub-title">
				当前会员到期时间
			</view>
			<view class="text">
				{{endTime}}
			</view>
		</view>
		<view class="middle-box">
			<view class="title">
				选择购买会员
			</view>
			<view class="item-box">
				<view class="item" :class="[current == index ? 'hover' : '']" v-for="(item,index) in vipList" :key="index" @click="buyVipTap(index)">
					<view class="name">
						{{item.name}}
					</view>
					<view class="money">
						<text>¥</text>{{item.money}}
					</view>
				</view>
			</view>
		</view>
		<view class="bottom-box">
			<view class="pay-type-box">
				<view class="title">
					选择支付方式
				</view>
				<view class="wechat-pay">
					<view class="left">
						<u--text prefixIcon="https://item.techolic.cn/hjf/Public/appimg/icon_wechat_pay.png"
							iconStyle="font-size: 22px;margin-right: 10rpx;width:44rpx;height:44rpx" size="32rpx"
							:bold="true" color="#000000" text="微信支付"></u--text>
					</view>
					<view class="right">
						<!-- <u-icon name="checkmark-circle" size="24"></u-icon> -->
						<u-icon name="checkmark-circle-fill" size="24" color="#ff8811"></u-icon>
					</view>
				</view>
			</view>
			<view class="btn-box" @click="pay">
				立即充值
			</view>
		</view>
		<view class="fgx"></view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				endTime:"",
				vipList: [],
				current: 0,
				
			}
		},
		onLoad() {
			let that = this;
			app.globalData.index_login = 1;
			app.login();
			that.get_data();
				
		},
		methods: {
			get_data(){
				var _this = this;
				
				app._get('user/get_vip', {
				}, function(res) {
					_this.vipList = res.vip;
					_this.customer = res.customer;
					_this.endTime = res.endtime;
				});
			},
			buyVipTap(index) {
				let that = this;
				that.current = index
			},
			pay() {
				console.log('购买');
				let that = this;
				var vipList = that.vipList;
				var current = that.current;
				app._post_form('user/vip_pay', {
					vid: vipList[current].id,
				}, function(res) {
					if (res.code == 200) {
						
						let js = res.js;
						
						console.log('res:::::');
						console.log(res);
						uni.requestPayment({
							'timeStamp': js.timeStamp,
							'nonceStr': js.nonceStr,
							'package': js.package,
							'signType': js.signType,
							'paySign': js.paySign,
							success: function(res) {
								app.showSuccess('支付成功', function() {
									that.get_data();
								});
							},
							fail: function() {
								// app._post_form('goods/not_pay', {
								// 	order_id: order_id,
								// 	cartList: cartList,
								// 	goods_id: res.goods_id,
								// 	goods_list: goodsInfo,
								// }, function(res) {
								// 	app.showError('支付取消', function() {
								// 		uni.redirectTo({
								// 			url: '../goodsOrderInfoPage/goodsOrderInfoPage'
								// 		})
								// 	});
								// });
							},
						})
						
						
					} else {
						app.showMsg(res.msg);
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.content {
		width: 750rpx;
		height: 580rpx;
		background-image: url('https://item.techolic.cn/hjf/Public/appimg/icon_buyvip_bg.png');
		background-repeat: no-repeat;
		background-size: cover;

		.head-box {
			height: 230rpx;
			padding: 84rpx 32rpx;

			.sub-title {
				margin-top: 40rpx;
				margin-bottom: 20rpx;
				font-size: 28rpx;
				color: rgba(#7C4608, 0.5);
			}

			.text {
				font-size: 56rpx;
				font-weight: bold;
				color: #7C4608;
			}
		}

		.middle-box {
			border-radius: 48rpx;
			background-color: #ffffff;
			padding: 48rpx 32rpx;

			.title {
				font-size: 32rpx;
				font-weight: bold;
				color: #1E182F;
				margin-bottom: 30rpx;
			}

			.item-box {
				display: flex;
				flex-wrap: wrap;
				align-content: flex-start;
				justify-content: space-between;

				.hover {
					background-color: #fff4e8;
					color: #ff8812;
					border: 2rpx solid #FF8811;
				}

				.item {
					width: 218rpx;
					height: 144rpx;
					margin-bottom: 16rpx;
					border-radius: 16rpx;
					text-align: center;
					border-radius: 16rpx;
					background-color: #F4F8F9;

					.name {
						margin-top: 20rpx;
						font-size: 36rpx;
						font-weight: bold;

					}

					.money {
						font-size: 32rpx;
						color: rgba(#1E182F, 0.7);

						text {
							font-size: 24rpx;
						}
					}
				}
			}

		}

		.bottom-box {
			margin: 0 32rpx;

			.pay-type-box {
				padding-bottom: 40rpx;

				.title {
					font-size: 32rpx;
					font-weight: bold;
					color: #1E182F;
					margin-bottom: 30rpx;
				}

				.wechat-pay {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin: 50rpx 0;

				}
			}

			.btn-box {
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				font-size: 32rpx;
				color: #ffffff;
				background-color: #FF8811;
				border-radius: 18rpx;
			}


		}

		.fgx {
			height: 150rpx;
		}
	}
</style>